package com.gw.vip.server.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gw.vip.server.po.HisTrans;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;

/**
 * @author GW
 * @description
 * @since 2022-05-10
 */
public interface HisTransMapper extends BaseMapper<HisTrans> {
    /**
     * 根据清算日期查询交易数量
     * @param clearDate
     * @return
     */
    @Select("SELECT COUNT(1) FROM his_trans WHERE clear_date=#{clearDate}")
    int countByClearDate(LocalDate clearDate);

    /**
     * tmpTransAcc表转hisTransAcc
     * @param clearDate
     */
    @Insert("INSERT INTO his_trans (SELECT * FROM tmp_trans WHERE clear_date=#{clearDate})")
    void tmpTransToHis(LocalDate clearDate);

    /**
     * 根据 orderId 查找交易
     * @param orderId
     * @return
     */
    @Select("SELECT * FROM his_trans WHERE order_id=#{orderId}")
    List<HisTrans> listByOrderId(String orderId);

    /**
     * 根据 clientTransId 获取流水
     * @param clientTransId
     * @return
     */
    @Select("SELECT * FROM his_trans WHERE client_trans_id=#{clientTransId}")
    HisTrans getByBase(String clientTransId);
}
